package com.wsc.wisdomchina.activitity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.CoordinateConverter;
import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.JsonTools;
import com.wsc.wisdomchina.activitity.baseactivity.BaseActivity;
import com.wsc.wisdomchina.callback.ContributorView;
import com.wsc.wisdomchina.constant.Constant;
import com.wsc.wisdomchina.javaBean.CommitteeDetailBean;
import com.wsc.wisdomchina.javaBean.RespObj;
import com.wsc.wisdomchina.presenter.ContributorPresenter;

import java.util.ArrayList;
import java.util.List;

public class JuWeiInfoDetailActivity extends BaseActivity implements View.OnClickListener, ContributorView {
    private ImageView regist_back;
    private TextView tv_title;
    private Context context;
    private ContributorPresenter contributorPresenter;
    private WebView webView;
    private String CommitteeInfoDetailFlag="CommitteeInfoDetailFlag";
//    private MapView mMapView;
//    private BaiduMap mBaiduMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.juweiinfodetail_layout);
        initView();
        context = this;
        contributorPresenter = new ContributorPresenter(this, this);
        Intent intent=getIntent();
        String id = intent.getStringExtra("id");
        String name=intent.getStringExtra("name");
        tv_title.setText(name);
        contributorPresenter.getCommitteeDetail(id, CommitteeInfoDetailFlag);

    }

    private void initView() {
        regist_back = (ImageView) findViewById(R.id.regist_back);
        regist_back.setOnClickListener(this);
        tv_title = (TextView) findViewById(R.id.tv_headtitle);
        webView = (WebView) findViewById(R.id.fragment_zxxq_webView);
//        //获取地图控件引用
//        mMapView = (MapView) findViewById(R.id.map);
//        mBaiduMap = mMapView.getMap();
//        // 开启定位图层
//        mBaiduMap.setMyLocationEnabled(true);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.regist_back:
                finish();
                break;
        }
    }

    @Override
    public void onLoadContributorStart(String flag) {

    }

    @Override
    public void onLoadContributorSuccess(String jsonString, String flag) {
        try {
            if (flag.equals(CommitteeInfoDetailFlag)) {
                RespObj respObj = JsonTools.jsonStringToObject(jsonString, RespObj.class);
                String code = respObj.getCode();
                Object object = respObj.getMessage();
                if (code.equals("200") && object != null) {
                    String messageJson = JsonTools.objectToJsonString(object);
                    CommitteeDetailBean newsDetailBean = JsonTools.jsonStringToObject(messageJson, CommitteeDetailBean.class);
//                                     final double lng=newsDetailBean.getLng();
//                    final double lat=newsDetailBean.getLat();
//                    LatLng sourceLatLng = new LatLng(lng,lat);
//                    List<OverlayOptions> var = new ArrayList();
//                    //定义Maker坐标点
//                    LatLng point = new LatLng(lng, lat);
//                    //构建Marker图标
//                    BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.mipmap.baoming_icon2x);
//                    //构建MarkerOption，用于在地图上添加Marker
//                    OverlayOptions option = new MarkerOptions()
//                            .position(point)
//                            .icon(bitmap);
//                    var.add(option);
//                    mBaiduMap.addOverlays(var);

                    String Url = Constant.Head_string + newsDetailBean.getContent() + Constant.foot_string;//URL编码数据
                    webView.getSettings().setDefaultTextEncodingName("UTF-8");
                    webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                    webView.getSettings().setLoadWithOverviewMode(false);
                    webView.loadData(Url, "text/html; charset=UTF-8", null);
                }
            }
        } catch (Exception e) {

        }
    }

    @Override
    public void onLoadContributorComplete(String flag) {
    }

    @Override
    public void onLoadContributorError(String error, String flag) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        mMapView.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
//        mMapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
//        mMapView.onPause();
    }
}
